<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/static/assets/css/layui.css">
    <script src="../../assets/jquery.min.js"></script>
    <title>固定车主管理-出入场设置</title>
</head>
<body class="layui-view-body">
固定车主管理-出入场设置
<input type="hidden" name="images" class="image" >
<div class="layui-form-item">
    <label class="layui-form-label ">照片:</label>
    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test1">上传图片</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo1">
            <p id="demoText"></p>
        </div>
    </div>
</div>
<script src="/static/assets/layui.all.js"></script>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/user/upload'
            ,auto:true
            ,size:50000
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result);
                });
            }
            ,done: function(res){
                var imgUrl = "localhost:8080/"+res.data.filePath
                $.ajax({
                    url:"/scanCarNum",
                    type:"post",
                    dataType:"json",
                    data:{
                        imgUrl:imgUrl
                    },
                    success:function (res) {
                        console.log(res)
                    }
                })
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                var demoText = $('#demoText');
                demoText.html('<span style="color: #4cae4c;">上传成功</span>');

                var fileupload = $(".image");
                fileupload.attr("value",res.data.src);
                console.log(fileupload.attr("value"));
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


    });
</script>
</body>
</html>
